/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.everdras.blackPlague;

import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import me.everdras.blackPlague.commands.CommandHandler;

/**
 *
 * @author Josh
 */
public class BlackPlague extends JavaPlugin {
    private static final Logger log = Logger.getLogger("Minecraft");
    private PlagueSpreadListener pslistener;
    

    @Override
    public void onDisable() {
        log.info("BlackPlague plugin unloaded.");
    }

    
    @Override
    public void onEnable() {
        //setupPermissions();
        
        PluginManager pm = getServer().getPluginManager();
        
        
        PlagueThread pt = new PlagueThread();
        pt.start();
        
        pslistener = new PlagueSpreadListener(pt);
        
        pm.registerEvent(org.bukkit.event.Event.Type.ENTITY_DEATH, pslistener, org.bukkit.event.Event.Priority.High, this);
        
        PluginDescriptionFile pdf = getDescription();
        
        log.info("BlackPlague plugin loaded.");
    }
    

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(!label.equals("bp"))
            return false;
        
        Player player = (Player) sender;
        
        if(args[0].equals("start")) {
            CommandHandler.startPlague(player, pslistener);
            return true;
        }
        else if(args[0].equals("end")) {
            CommandHandler.endPlague(player, pslistener.getPlagueThread());
            return true;
        }
        else if(args[0].equals("infect")) {
            try {
                CommandHandler.infect(pslistener.getPlagueThread(), player, this.getServer().getPlayer(args[1]));
                
            }
            catch(Exception e) {
                player.sendMessage("/bp infect playername");
            }
            return true;
        }
        else if(args[0].equals("cure")) {
            try {
                CommandHandler.cure(pslistener.getPlagueThread(), player, getServer().getPlayer(args[1]));
            } catch (Exception e) {
                player.sendMessage("/bp cure playername");
            }
            return true;
            
        }
        
        
        
        return false;
    }
    
    
}
